package com.lq.ecoldchain.ui.main.orderlist.orderpay

import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewdelegate.BaseViewDelegate
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.toast

/*
*2019/1/17 0017  18:01
*function by lq
*/
class OrderPayViewModel:BaseViewDelegate(){

    var id:Int=0
    private var payWay =1
    val weChatPay by lazy { MutableLiveData<Boolean>() }
    val url by lazy { MutableLiveData<String>() }

    init {
        weChatPay.value = true
    }

    fun wxPay(){
        payWay= 2
        weChatPay.value = false
        toast { "切换微信收款二维码" }
        code()
    }

    fun payBao(){
        payWay=1
        weChatPay.value = true
        toast { "切换支付宝收款二维码" }
        code()
    }

    fun code(){
        BaseNetCore.ApiServiceImpl.obtainCode(id,payWay).compose(RxTransformer.switchSchedulers()).subscribe(object:BaseObserver<String>(){
            override fun onSuccess(t: String?) {
                url.value = "http://mobile.qq.com/qrcode?url=$t"
            }

            override fun onFail(code: String) {}
        })
    }

}